home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / CDICTION / CSMARTDO.C < prev    next >
Text File  |  1989-09-15  |  4KB  |  133 lines

  1. /*****************************************************************************
  2. CSmartDocument.c
  3.  
  4.     see header for more information
  5.     
  6. SUPERCLASS = CSmartDocument
  7. *****************************************************************************/
  8.  
  9. #include "CSmartDocument.h"
  10. #include "CList.h"
  11.  
  12. extern    CBureaucrat    *gGopher;
  13. /*****************************************************************************/
  14. void CSmartDocument::ISmartDocument(CBureaucrat *aSupervisor, 
  15.                 Boolean printable, Boolean closeDisposes)
  16. {
  17.     CDocument::IDocument( aSupervisor, printable);
  18.     
  19.     /* create list for edit text items */
  20.     
  21.     itsEditItems = new( CList);
  22.     itsEditItems->IList();
  23.     
  24.     this->closeDisposes = closeDisposes;
  25.     
  26. }    /* CSmartDocument::ISmartDocument */
  27. /*****************************************************************************/
  28. void CSmartDocument::AddEditItem( CSmartEditText *anEditItem)
  29. {
  30.     /* add item to list of editable text items */
  31.     
  32.     itsEditItems->Append( anEditItem);
  33.  
  34. }    /*  CSmartDocument::AddEditItem */
  35. /*****************************************************************************/
  36. void CSmartDocument::ActivateEditItem( CSmartEditText *anEditText)
  37. {
  38.  
  39.     if (itsActiveText) itsActiveText->SetTarget( FALSE);
  40.     itsActiveText = anEditText;    /* NOTE: could be NIL */
  41.     if (anEditText)    
  42.     {
  43.         anEditText->SetTarget( TRUE);
  44.         itsGopher = anEditText;
  45.     }
  46.     else itsGopher = this; /* if NIL then gopher is the document */
  47.     
  48.     if (active) gGopher = itsGopher; /* if we're active set the
  49.                                         global gopher */
  50.      
  51. }    /* CSmartDocument::ActivateEditItem */
  52. /*****************************************************************************/
  53. void CSmartDocument::ActivateNextEditItem( CSmartEditText *currItem)
  54. /*
  55.     activate next item in list, as in tabbing thru items.
  56. */
  57. {    Int32    nextIndex;
  58.     CSmartEditText *nextEdit;
  59.     Boolean    foundVisible = false;
  60.     
  61.     /* search list for next editable text item that is visible and editable */
  62.     
  63.     nextEdit = currItem;
  64.     while (!foundVisible)
  65.     {
  66.         nextIndex = itsEditItems->FindIndex( nextEdit) + 1;
  67.         nextEdit = (CSmartEditText *) itsEditItems->NthItem( nextIndex);
  68.         if (nextEdit == currItem)
  69.         { /* we've wrapped around */
  70.         
  71.             nextEdit = NIL;
  72.             break;
  73.         }
  74.         if (!nextEdit) nextEdit = (CSmartEditText *) itsEditItems->FirstItem();
  75.         foundVisible = nextEdit->ReallyVisible() && nextEdit->IsEditable();
  76.     
  77.     }
  78.     if ((nextEdit != NIL)&&(nextEdit != currItem))
  79.     {
  80.         ActivateEditItem( nextEdit);
  81.         nextEdit->SelectAll();
  82.     }
  83.  
  84. }    /* CSmartDocument::ActivateNextEditItem */
  85. /*****************************************************************************/
  86. void CSmartDocument::SelectWindow( void)
  87. {
  88.     if (itsWindow) itsWindow->Select();
  89.  
  90. }    /* CSmartDocument::SelectWindow */
  91. /*****************************************************************************/
  92. void CSmartDocument::HideWindow( void)
  93. {
  94.     if (itsWindow) itsWindow->Hide();
  95.  
  96. }    /* CSmartDocument::HideWindow */
  97. /*****************************************************************************/
  98. Boolean CSmartDocument::Close( Boolean Quitting)
  99. {
  100.     Boolean continueFlag = TRUE;
  101.     
  102.     if (closeDisposes)
  103.         continueFlag =  inherited::Close( Quitting);
  104.     else HideWindow();
  105.     
  106.     return continueFlag;
  107.  
  108. }    /* CSmartDocument::CloseWind */
  109. /*****************************************************************************/
  110. void CSmartDocument::SetReturnGopher( CBureaucrat *aReturnGopher)
  111. {
  112.     itsReturnGopher = aReturnGopher;
  113.  
  114. }    /* CSmartDocument::SetReturnGopher */
  115. /*****************************************************************************/
  116. void CSmartDocument::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  117. {
  118.     if ((theChar == kCR)||(theChar == kEnter))
  119.     {
  120.         if (itsReturnGopher)
  121.             itsReturnGopher->DoKeyDown( theChar, keyCode, macEvent);
  122.     }
  123.  
  124. }    /* CSmartDocument::DoKeyDown */
  125. /*****************************************************************************/
  126. void CSmartDocument::Dispose( void)
  127. {
  128.     itsEditItems->Dispose(); /* dispose list but not items, superclass does that */
  129.     inherited::Dispose();
  130.  
  131. }    /* CSmartDocument::Dispose */
  132. /*****************************************************************************/
  133.